package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RySalesSummary;
import com.ruoyi.pims.service.IRySalesSummaryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售汇总Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/summary")
public class RySalesSummaryController extends BaseController
{
    private String prefix = "pims/summary";

    @Autowired
    private IRySalesSummaryService rySalesSummaryService;

    @RequiresPermissions("pims:summary:view")
    @GetMapping()
    public String summary()
    {
        return prefix + "/summary";
    }

    /**
     * 查询销售汇总列表
     */
    @RequiresPermissions("pims:summary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RySalesSummary rySalesSummary)
    {
        startPage();
        List<RySalesSummary> list = rySalesSummaryService.selectRySalesSummaryList(rySalesSummary);
        return getDataTable(list);
    }

    /**
     * 导出销售汇总列表
     */
    @RequiresPermissions("pims:summary:export")
    @Log(title = "销售汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RySalesSummary rySalesSummary)
    {
        List<RySalesSummary> list = rySalesSummaryService.selectRySalesSummaryList(rySalesSummary);
        ExcelUtil<RySalesSummary> util = new ExcelUtil<RySalesSummary>(RySalesSummary.class);
        return util.exportExcel(list, "销售汇总数据");
    }

    /**
     * 新增销售汇总
     */
    @RequiresPermissions("pims:summary:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售汇总
     */
    @RequiresPermissions("pims:summary:add")
    @Log(title = "销售汇总", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RySalesSummary rySalesSummary)
    {
        return toAjax(rySalesSummaryService.insertRySalesSummary(rySalesSummary));
    }

    /**
     * 修改销售汇总
     */
    @RequiresPermissions("pims:summary:edit")
    @GetMapping("/edit/{summaryId}")
    public String edit(@PathVariable("summaryId") Long summaryId, ModelMap mmap)
    {
        RySalesSummary rySalesSummary = rySalesSummaryService.selectRySalesSummaryBySummaryId(summaryId);
        mmap.put("rySalesSummary", rySalesSummary);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售汇总
     */
    @RequiresPermissions("pims:summary:edit")
    @Log(title = "销售汇总", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RySalesSummary rySalesSummary)
    {
        return toAjax(rySalesSummaryService.updateRySalesSummary(rySalesSummary));
    }

    /**
     * 删除销售汇总
     */
    @RequiresPermissions("pims:summary:remove")
    @Log(title = "销售汇总", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rySalesSummaryService.deleteRySalesSummaryBySummaryIds(ids));
    }
}
